import maya.cmds as cmds
import os

theFile = os.path.basename(cmds.file(q=1, l=1)[0]).split(".")[0]

def pb(delAvi = True):
    sf = cmds.playbackOptions(q=1, minTime=1)
    ef = cmds.playbackOptions(q=1, maxTime=1)   
    
    avi = r'X:/Works/3d/ant/playblast/' + theFile + ".avi"    
    
    if '64' in cmds.about(v=1):
        MAYA_BIT = '64'
    else:
	MAYA_BIT = '32'

    if MAYA_BIT == '32':
        cmds.playblast( f=avi , p=100 , fmt='qt' , st=sf, et=ef, wh=[0,0],
                       v=1, c='H.264', qlt=100, fo=1 )
    else :
        cmds.playblast( f=avi, p=100,  fmt='avi', st=sf, et=ef, wh=[0,0],
                       v=1, qlt=100, fo=1 , os= 1 )
    encoding(avi , delAvi = delAvi )
    #theFFmpeg = r"X:\Utils\2D\FFmpeg\ffmpeg.exe"
    ##cmd = theFFmpeg+" -i "+avi+" -vcodec libx264  -y "+mov
    #cmd = theFFmpeg+" -i "+avi+" -b 10000k  -vcodec libx264 -s hd720 -y "+mov
    #os.system( cmd )
    ##aa = subprocess.Popen(cmd , shell=1 , stdout=subprocess.PIPE)
    ##print aa.stdout.read()
    #os.system("del %s" % avi.replace('/' , '\\'))
    #os.system( mov ) 
    #print "Done!"

def encoding(path , delAvi = True):
    mov = r'X:/Works/3d/ant/playblast/' + theFile + ".mov"
    theFFmpeg = r"X:\Utils\2D\FFmpeg\ffmpeg.exe"
    #cmd = theFFmpeg+" -i "+avi+" -vcodec libx264  -y "+mov
    cmd = theFFmpeg+" -i " + path + " -b 10000k  -vcodec libx264 -s hd720 -y "+mov
    os.system( cmd )
    if delAvi:
	os.system("del %s" % path.replace('/' , '\\'))
    os.system( mov )